class Product < ActiveRecord::Base
  belongs_to:shop
  has_many:line_items
  has_many:productcomment
  
  #check vilidation
  validates_presence_of:title,:description,:price
  validates_uniqueness_of:title
  validates_numericality_of:price,:amount
  validates_format_of:img_url,
                        :with=> %r{\.(gif|jpg|jpeg|png)$},
                        :message=>"must be a URL for a GIF,JPG,JPEG or PNG image"
  
  protected
  def validate
    errors.add(:price,"should be at least 0.01") if price.nil? || price<0.01
    errors.add(:amount,"should be at least 0") if amount.nil? || amount<0 
  end
end
